package app.beit.finportal.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import app.beit.finportal.entity.Account;

public class AccountDao extends BaseDao<Account>{
	
	@SuppressWarnings("unchecked")
	public List<Account> getAccount(final String username, final String password) throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query query = session.createQuery("from Account where username=:username and password=:password");
		query.setParameter("username", username);
		query.setParameter("password", password);
		final List<Account> results = query.list();
		session.close();
		
		return results;
	}
	
	@SuppressWarnings("unchecked")
	public List<Account> getAccount(final String username) throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query query = session.createQuery("from Account where username=:username");
		query.setParameter("username", username);
		final List<Account> results = query.list();
		session.close();
		
		return results;
	}
	
	@SuppressWarnings("unchecked")
	public List<Account> getAll() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final List<Account> result = session.createQuery("from Account").list();
		session.close();
		
		return result;
	}
	
}
